//
//  NSWLMInfoPopView.m
//  Meboo
//
//  Created by kyo on 2024/4/30.
//

#import "NSWLMInfoPopView.h"
@interface NSWLMInfoPopView ()
<
UIGestureRecognizerDelegate
>
@property (nonatomic, strong) UIImageView *arrowImageView;
@property (nonatomic, strong) UIImageView *backImageView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *subTitleLab;

@property(nonatomic,strong) UILabel *titleLab1;
@property(nonatomic,strong) UIButton *infoBtn;
@end

@implementation NSWLMInfoPopView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}


#pragma mark - Action
- (void)closeAction {
    self.hidden = YES;
    if (self.closeBlock) {
        self.closeBlock();
    }
}

#pragma mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    if ([touch.view isDescendantOfView: self.backImageView]) {
        return NO;
    }
    return YES;
}

#pragma mark - UI
- (void)setupUI {
    self.hidden = YES;
    self.backgroundColor = [UIColor colorWithRed:0 / 255.0 green:0 / 255.0 blue:0 / 255.0 alpha:0.5];
    
    UITapGestureRecognizer *actionTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeAction)];
    actionTap.delegate = self;
    [self addGestureRecognizer:actionTap];
    
    [self addSubview:self.titleLab1];
    [self.titleLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(StatusBarHeight+MBHeightScale(6));
        make.left.mas_equalTo(MBWidthScale(24));
    }];
    
    [self addSubview:self.infoBtn];
    [self.infoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLab1);
//        make.centerX.equalTo(self.mas_left).offset((ScreenWidth-MBWidthScale(74))*3/5+MBWidthScale(37));
        make.left.equalTo(self.titleLab1.mas_right).offset(MBWidthScale(3));
        make.width.height.mas_equalTo(MBHeightScale(17));
    }];
    
    [self addSubview:self.arrowImageView];
    [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.infoBtn);
        make.top.equalTo(self.infoBtn.mas_bottom).offset(MBHeightScale(14));
    }];
    
    [self addSubview:self.backImageView];
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(37));
        make.right.mas_equalTo(MBWidthScale(-37));
        make.top.equalTo(self.arrowImageView.mas_bottom).offset(MBHeightScale(-2));
    }];
    
    [self.backImageView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(24));
        make.right.mas_equalTo(MBWidthScale(-24));
        make.top.mas_equalTo(MBHeightScale(30));
        make.centerX.equalTo(self.backImageView);
    }];
    
    [self.backImageView addSubview:self.subTitleLab];
    [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLab.mas_bottom).offset(MBHeightScale(11));
        make.left.mas_equalTo(MBWidthScale(24));
        make.right.mas_equalTo(MBWidthScale(-24));
        make.bottom.mas_equalTo(MBWidthScale(-28));
    }];
}

#pragma mark - Setter && Getter

- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [UIImageView new];
        _arrowImageView.userInteractionEnabled = YES;
        _arrowImageView.image = ImageWithName(@"wlm_header_infopop_arrow");
    }
    return _arrowImageView;
}

- (UIImageView *)backImageView {
    if (!_backImageView) {
        _backImageView = [UIImageView new];
        _backImageView.userInteractionEnabled = YES;
        _backImageView.contentMode = UIViewContentModeScaleAspectFill;
        _backImageView.image = ImageWithName(@"wlm_header_infopop_back");
    }
    return _backImageView;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.numberOfLines = 0;
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.text = @"What is ‘Who Likes Me’ ?";
        _titleLab.font = MBHelBoldFontSizeScale(18);
        _titleLab.textColor = HEXS(@"B92176");
    }
    return _titleLab;
}

- (UILabel *)subTitleLab {
    if (!_subTitleLab) {
        _subTitleLab = [UILabel new];
        _subTitleLab.numberOfLines = 0;
        _subTitleLab.textAlignment = NSTextAlignmentCenter;
        _subTitleLab.text = @"Freely view those who have crush on you and build sexy relationships quickly 😉";
        _subTitleLab.font = MBHelFontSizeScale(14);
        _subTitleLab.textColor = HEXS(@"000000");
    }
    return _subTitleLab;
}

- (UILabel *)titleLab1 {
    if (!_titleLab1) {
        _titleLab1 = [UILabel new];
        _titleLab1.hidden = YES;
        _titleLab1.text = @"Who Like Me";
        _titleLab1.font = PDBoldScale(30);
        _titleLab1.textColor = HEXS(@"B92176");
    }
    return _titleLab1;
}

- (UIButton *)infoBtn {
    if (!_infoBtn) {
        _infoBtn = [UIButton new];
        _infoBtn.hidden = YES;
        [_infoBtn setYXEnlargeEdgeWithTop:20 right:20 bottom:20 left:20];
        [_infoBtn setImage:ImageWithName(@"wlm_header_info_normal") forState:0];
    }
    return _infoBtn;
}
@end
